package com.example.definedview;

import androidx.appcompat.app.AppCompatActivity;
import androidx.databinding.DataBindingUtil;

import android.os.Bundle;
import android.view.View;

import com.example.definedview.databinding.ActivityStateBinding;

public class StateActivity extends AppCompatActivity {
    ActivityStateBinding activityStateBinding;
    Boolean flag = false;

    //状态指示灯
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //setContentView(R.layout.activity_state);
        activityStateBinding = DataBindingUtil.setContentView(this, R.layout.activity_state);
        activityStateBinding.toggle.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                flag = !flag;
                if(flag){
                    activityStateBinding.warning.setVisibility(View.INVISIBLE);
                    activityStateBinding.door.setImageResource(R.drawable.door);
                    activityStateBinding.r1.setImageResource(R.drawable.stop);
                    activityStateBinding.r2.setImageResource(R.drawable.stop);
                    activityStateBinding.r3.setImageResource(R.drawable.stop);
                }else{
                    activityStateBinding.warning.setVisibility(View.VISIBLE);
                    activityStateBinding.door.setImageResource(R.drawable.door_open);
                    activityStateBinding.r1.setImageResource(R.drawable.app_mw_app_running_env);
                    activityStateBinding.r2.setImageResource(R.drawable.app_mw_app_running_env);
                    activityStateBinding.r3.setImageResource(R.drawable.app_mw_app_running_env);
                }
            }
        });
    }
}
